<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
$shop=$this->plugin_setting('shop');
$return['shopset']=$shop;
$keywords=$this->plugin_setting('search');
if($_RQ['op']=='main'){
	$ordersn=$_RQ['ordersn'];
	if (empty($ordersn)) {
		exi('请输入进场码!','error','jy_qiuyuyue/manage.order/');
	}
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$order=$this->pdo_get('server_order',array('ordersn'=>$ordersn));
	if (empty($order)) {
		exi('进场码错误,无权核销','error','jy_qiuyuyue/manage.order/');   
	}
	//核销店员身份
	$prams=array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if($order['store_id']){
		$prams['store_id']=$order['store_id'];
	}
	$saler=pdo_get('jy_qiuyuyue_staff',$prams);
	if (empty($saler)) 
	{
		exi('您不是该店核销员/配送员,无权核销','error','jy_qiuyuyue/manage.order/');   
	}
	if($order['status']==0 || $order['status']==4){
		exi('订单未付款或已关闭!','error','jy_qiuyuyue/manage.order/');
	}
	if($order['status']==4){
		exi('订单已关闭，不能核销！','error','jy_qiuyuyue/manage.order/');
	}elseif($order['status']==5){
		exi('订单已申请退款，不能核销！','error','jy_qiuyuyue/manage.order/');
	}elseif($order['status']==5){
		exi('订单已退款，不能核销！','error','jy_qiuyuyue/manage.order/');
	}
	if ($order['status'] ==2) {	
		exi('该客户已进场!','error','jy_qiuyuyue/manage.order/');		
	}
	$return['post']=array(
		'orderid'=>$order['id'],
		'ordersn'=>$ordersn,
	);
	$serve=pdo_get('jy_qiuyuyue_serve',array('id'=>$order['serve_id'],'uniacid'=>$_SESSION['uniacid']));
	$order['store']=pdo_get('jy_qiuyuyue_store',array('id'=>$order['store_id'],'uniacid'=>$_SESSION['uniacid']));
	$order['user_name']=$member['nickname'];
	$order['user_mobile']=$member['mobile'];
	$order['serve_title']=$serve['title'];
	$order['serve_image']=$serve['image'];
	$order['plate']=pdo_get('jy_qiuyuyue_serve_plate',array('id'=>intval($order['plate_id']),'uniacid'=>$_SESSION['uniacid']),array('title'));
	$order['createtime']=date('Y-m-d H:i:s', $order['createtime']);
	$order['serve_typetitle']=$this->serve_types[$order['serve_type']];
	$serve_times=json_decode($serve['serve_time'],true);
	$order['serve_time']=$serve_times[$order['timeid']];
	$return['order']=$order;
	set_html('title','核销进场');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$ordersn=trim($post['ordersn']);
	if(!$ordersn){
		exi('订单不存在，请重新选择订单','error');
	}
	$update=array('status'=>'2');
	$this->update('server_order',$update,array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>$ordersn));
	exi('已确认用户进场！','','jy_qiuyuyue/manage.order/');
}